// 解构(key)赋值
// 改名:
// 默认值=
/*
let {name:name1,age,address='cd'} = {name:'zf',age:10}
console.log(name1,address);
let [n,a] = ['ahhh',10];
console.log(n,a);
*/

//缺省
/*
let [, age] = ['ahhh', 10];
console.log(age);
*/

//左右两边结构并不一定要相同
/*let {length} = [];
console.log(length);*/

// 对象里面套数组 数组里套对象
/*
let {school:{count}} = {school:{count:100}};
console.log(count)
*/

// 一般会和`...`一起用(剩余运算符 , 展开运算符)
// 1)... 剩余运算符,只能放到最后一项
/*
let [,...args] = ['ahhh','10','cd'];
let {name,...obj} = {name:'ahhh',age:10,address:'cd'};
console.log(obj);
*/

// 2) ... 方法传递参数连用,可以把对象或者数组展开
/*
let r = Math.max(...[1,2,3,5]);
console.log(r);
*/


//浅拷贝
/*let obj = {name: 'ahhh', age: {n: 10}};
let obj1 = {...obj}  // 等同于 → Object.assign(obj)
obj1.age.n = 100;
console.log(obj);

let arr = [1,2,3,[4]]; // slice是浅拷贝，截取的是引用地址
let newArr = arr.slice(3);
newArr[0][0] = 100;
console.log(arr);*/

//深拷贝
//JSON.stringify() 只能拷贝 纯对象 会把函数 reg这些对象丢弃掉


// 实现一个方法 做一个 mergeOptions
/*let obj1 = {name:{a:1}};
let obj2 = {age:10,name:{b:2}}; // {...obj1,...obj2}
mergeOptions(obj1,obj2) // {age:10,name:{a:1,b:2}}
console.log({...obj1,...obj2});*/

